package logic

import (
	"context"

	"go-weixin/app/guitar/model"
	"go-weixin/app/guitar/rpc/internal/svc"
	"go-weixin/app/guitar/rpc/pb/proto/guitar"

	"github.com/zeromicro/x/errors"

	"github.com/zeromicro/go-zero/core/logx"
)

type GuitarUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGuitarUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GuitarUpdateLogic {
	return &GuitarUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GuitarUpdateLogic) GuitarUpdate(in *guitar.GuitarUpdateReq) (*guitar.GuitarUpdateResp, error) {
	accected, err := l.svcCtx.ChenDb.ID(in.Id).Update(&model.GuitarModel{Title: in.Title})
	if err != nil {
		return nil, errors.New(8000, "guitar.update.err."+err.Error())
	}
	if accected == 0 {
		return nil, errors.New(7000, "guitar.update受影响行数0")
	}

	return &guitar.GuitarUpdateResp{}, nil
}
